<%@page import="org.springframework.data.domain.Page"%>
<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<style>
<!--
.paging{
	margin: auto;
	text-align: center;
	background-color: #FEF9E7;
}
.paging a{
	text-decoration: none;
}
.paging span{
	margin: 0px 3px;
	text-align: center;
}
.paging i{
	margin: 0px 2px;
	text-align: center;
	font-style: normal;
}
.paging .total{
	margin-left: 100px;
	text-align: center;
	font-style: normal;
}
-->
</style>
<%
//循环找出Page对象
 Enumeration<String> names = request.getAttributeNames();
Page pageResult = null;
while(names.hasMoreElements()){
	String name = names.nextElement();
	Object obj = request.getAttribute(name);
	if(obj instanceof Page){
		pageResult = (Page)obj;
		break;
	}
}
if(pageResult!= null){
	out.print("<div class='paging'>");
	if(pageResult.getTotalElements()>0){
		//开始输出翻页信息
		if(pageResult.hasPrevious()){
			//上一页
			out.print("<span><a href='javascript:void(0);' page='"+(pageResult.getNumber() - 1)+"'>上一页</a></span>");
		}
		int _count = 0;
		//当前页之前
		for(int i = 3; i > 0; i--){
			int p = pageResult.getNumber() - i;
			if(p>-1){
				_count++;
				out.print("<span><a href='javascript:void(0);' page='"+p+"'>"+(p+1)+"</a></span>");
			}
		}
		//输出当前页
		out.print(pageResult.getNumber()+1);
		//输出后面的翻页
		for(int i = 1;i<8-_count;i++){
			int p = pageResult.getNumber() + i;
			if(p<pageResult.getTotalPages()){
				out.print("<span><a href='javascript:void(0);' page='"+p+"'>"+(p+1)+"</a></span>");
			}
		}
		//输出下一页
		if(pageResult.hasNext()){
			out.print("<span><a href='javascript:void(0);' page='"+(pageResult.getNumber() + 1)+"'>下一页</a></span>");
		}
	}
	out.print("<span class='total'><i>共"+pageResult.getTotalElements()+"条记录</i><i>共"+pageResult.getTotalPages()+"页</i></span>");
	out.print("</div>");
}
%>

<script type="text/javascript">
$(document).ready(function(){
	var listForm = $('#listForm');
	if(listForm.length > 0){
		//翻页操作
		$('.paging a[page]').click(function(){
			var _this = $(this);
			var url = listForm.attr('action');
			if(url.indexOf('?')<0){//没有?
				url += "?";
			}else{
				url +="&";
			}
			listForm.append("<input type='hidden' name='page' value=''/>");
			url+="page="+_this.attr('page');
			listForm.attr('action',url);
			alert(listForm.attr('action'));
			listForm.submit();
		});
	}
});
</script>